package com.wealth.scsj.b_app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.xlhratingbar_lib.XLHRatingBar;
import com.wealth.scsj.b_app.R;
import com.wealth.scsj.b_app.bean.RightCommBean;
import com.wealth.scsj.b_app.bean.UserEvaluateListBean;
import com.wealth.scsj.b_app.utils.GlideRoundTransformUtil;
import com.wealth.scsj.b_app.utils.Tool;

import java.util.ArrayList;
import java.util.List;

/**
 *  右侧评论列表
 */

public class LeftCommAdapter extends BaseQuickAdapter<UserEvaluateListBean.DataBean, BaseViewHolder> {
    //加载图片评论布局
    private LinearLayout reputationImgLayout;
    private Context mContext;
    private List data;

    //测试用图片集合
    private List <UserEvaluateListBean.DataBean.ResourceInfoResponseModelsBean>imgLists= new ArrayList();

    public LeftCommAdapter(Context mContext, List data) {
        super(R.layout.item_comment_layout, data);
        this.mContext = mContext;
        this.data= data;
    }

    @Override
    protected void convert(BaseViewHolder helper, UserEvaluateListBean.DataBean item) {
        int revertState= item.getRevertState();
        if (0== revertState){
            //未回复
        }else {
            //已回复
        }
        //昵称
        helper.setText(R.id.nickname_tv,item.getNickName());
        //评价时间
        helper.setText(R.id.goods_detail_time_tv,item.getGevalAddtime());
        //评价商品
        helper.setText(R.id.goods_detail_name_tv,"评价商品:"+item.getGoodsName());
        //商品数量
        helper.setText(R.id.goods_num_tv,"×"+item.getBuyNum());
        //评价内容
        helper.setText(R.id.goods_detail_reputation_describe_tv,item.getGevalContent());
        //店家回复内容
        helper.setText(R.id.shopkeeper_replies_tv, (CharSequence) item.getGevalExplain());
        //星星评级
        XLHRatingBar ratingBar= helper.getView(R.id.ratingBar);
        int starScore= item.getGevalScoresService();
        ratingBar.setCountNum(starScore/2);

        imgLists= item.getResourceInfoResponseModels();
        reputationImgLayout= helper.getView(R.id.goods_detail_add_view_tv);
        /**
         * 添加评论
         */
        addReputationImg(imgLists);
    }

    private void addReputationImg(List<UserEvaluateListBean.DataBean.ResourceInfoResponseModelsBean> listImg) {
        if (reputationImgLayout.getChildCount()>0){
            reputationImgLayout.removeAllViews();
        }
        for (int i = 0; i < listImg.size(); i++) {

            View view = LayoutInflater.from(mContext).inflate(R.layout.item_compution_img_layout,null);

            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    240, 240);
            lp.setMargins(0, 0, Tool.dip2px(mContext, 10), 10);
            view.setLayoutParams(lp);

            ImageView reputationIv = view.findViewById(R.id.reputation_img);

            Glide
                    .with(mContext)
                    .load(listImg.get(i).getUrlFrameCapture())
                    .transform(new GlideRoundTransformUtil(mContext, 2))
                    .placeholder(R.mipmap.default_good_ic)
                    .error(R.mipmap.default_good_ic)
                    .into(reputationIv);

            reputationImgLayout.addView(view);

        }
    }
}
